package com.wt.router;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * @Auther: wtt
 * @Date: 2022/1/22 12:27
 * @Description:
 */
public class ZookeeperClient {
    private final CuratorFramework clinet;
    private static ZookeeperClient INSTANCE;

    static {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy);
        INSTANCE = new ZookeeperClient(curatorFramework);
        curatorFramework.start();
    }


    public ZookeeperClient(CuratorFramework curatorFramework) {
        this.clinet = curatorFramework;
    }

    public static CuratorFramework getClient() {
        return INSTANCE.clinet;
    }
}
